﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Project
{
    public partial class Login : Form
    {
        bool loginshow;
        
        public Login()
        {
            InitializeComponent();
           
        }
        bool capslock;


        public void lgn()
        {
            if (loginshow)
            {
                var myNextForm = new Main();
                myNextForm.Show();
                this.Dispose();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            capslock = Console.CapsLock;
            if (capslock == true)
            {
                lblStatus1.ForeColor = System.Drawing.Color.Green; 
                lblStatus1.Text = "ON"; 
                return base.ProcessCmdKey(ref msg, keyData);
            }
            else
            {
                lblStatus1.ForeColor = System.Drawing.Color.Red; 
                lblStatus1.Text = "OFF";
                return base.ProcessCmdKey(ref msg, keyData);
            } 
                       
        }

        private void capsChecker()
        {
            capslock = Console.CapsLock;
            if (capslock == true)
            {
                lblStatus1.ForeColor = System.Drawing.Color.Green;
                lblStatus1.Text = "ON";

            }
            else
            {
                lblStatus1.ForeColor = System.Drawing.Color.Red;
                lblStatus1.Text = "OFF";

            } 
        }

        
        
        private void Form1_Load(object sender, EventArgs e)
        {
            capsChecker();
            loginshow = Properties.Settings.Default.login;





            
        }

        private void btnLogin_Click(object sender, EventArgs e) // Checks if User exsits or not by calling a method and if user exists it shows next screen otherwise shows error message.
        {
            string Result = LoginCheck(txtPAss.Text);
            
            if (Result == "True") 
            {
                var myNextForm = new Main();
                myNextForm.Show();
                this.Close();
             }
            else
            {
                MessageBox.Show("Error: User not found");
            }
        }

        private string LoginCheck( string pass) // Checks if user exsits or not. If exist it returns True otherwise False.
        {

            string check = Properties.Settings.Default.pass.ToString(); 
            
            if (pass == check)
            {
                return "True";
            }
            else
            {
                return "False";
            }
        }

     

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            
        }

        private void button1_Click_2(object sender, EventArgs e)
        {
          
        }
    }
}
